Batch Data Query Method and Apparatus

ABSTRACT

A batch data query method and apparatus are provided. According to the method, multiple logical query plan trees corresponding to multiple query statements are obtained. The multiple logical query plan trees are divided into multiple query groups according to operators of each logical query plan tree. Logical query plan trees in each query group have the following relationship: an inter-query write-read dependency relationship, an operator overlap relationship, or an operand overlap relationship. Then, inter-query optimization is performed on the logical query plan trees in each query group, and multiple corresponding physical query plan trees are generated according to the multiple optimized logical query plan trees. Finally, physical queries are executed according to the multiple physical query plan trees, to obtain query results of the multiple query statements.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of International Application No.PCT/CN2015/094948, filed on Nov. 18, 2015, which claims priority toChinese Patent Application No. 201410673523.2, filed on Nov. 21, 2014.The disclosures of the aforementioned applications are herebyincorporated by reference in their entireties.

TECHNICAL FIELD

Embodiments of the present disclosure relate to data warehouse queryoptimization technologies, and in particular, to a batch data querymethod and apparatus.

BACKGROUND

Currently, a representative big data query system (for example, Hive,Shark, or Impala) uses a single query statement as a base unit ofparsing and optimization. A basic query processing procedure of the bigdata query system is as follows: first, a single read-in query statementis parsed into a logical query plan tree of a tree-like structure; then,an implementation algorithm is selected for each operator of the logicalquery plan tree, and an execution sequence of these operators isdetermined, so as to convert the logical query plan tree into a physicalquery plan; finally, a query execute engine executes the physical queryplan and outputs a query result.

Key performance of the big data query system is query efficiency.Currently, a frequently used method for improving query efficiency of abig data query system is mainly to equivalently transform a logicalquery plan tree, so as to reduce a quantity of tasks in a physical queryplan and to reduce an execution overhead of the tasks (which includesreducing read/write frequency of a file system, controlling an amount ofdata transmitted in a network and a calculation amount of a queryoperation, and the like). However, in a data warehouse (DWH) batch queryscenario, a problem of insufficient optimization opportunities exists ina conventional processing mode in which a single query statement is usedas a base unit of parsing and optimization. For example, task flowcorrelation optimization that is newly added to a Hive 0.12 version canbring acceleration for only three cases in total 22 query cases of astandard test set Transaction Processing Performance Council benchmark H(TPC-H), and has a specific requirement for a write manner of the cases.

Abundant inter-query optimization opportunities presented in the datawarehouse batch query application scenario are in sharp contrast toinsufficient intra-query optimization opportunities. The inter-queryoptimization opportunity is an optimization opportunity that existsbetween multiple query statements. In the batch query applicationscenario, a probability that similar query statements exist in the querystatements is relatively high. Therefore, there is a large quantity ofquery optimization opportunities. However, in the prior art, queryoptimization is performed only on a single query statement. As a result,a big data query has low query efficiency.

SUMMARY

Embodiments of the present disclosure provide a batch data query methodand apparatus to improve batch data query efficiency.

A first aspect of the present disclosure provides a batch data querymethod, including obtaining multiple logical query plan treescorresponding to multiple query statements, where each query statementis corresponding to one logical query plan tree, each logical query plantree in the multiple logical query plan trees includes multipleoperators, and each operator of each logical query plan tree includes atleast one operand. The method also includes dividing the multiplelogical query plan trees into multiple query groups according tooperators of each logical query plan tree, where logical query plantrees in each query group have the following relationship: aninter-query write-read dependency relationship, an operator overlaprelationship, or an operand overlap relationship. Additionally, themethod includes performing inter-query optimization on the logical queryplan trees in each query group; generating multiple physical query plantrees corresponding to the multiple optimized logical query plan trees;and executing physical queries according to the multiple physical queryplan trees, to obtain query results of the multiple query statements.

According to the batch data query method and apparatus in theembodiments of the present disclosure, multiple logical query plan treescorresponding to multiple query statements are obtained. The multiplelogical query plan trees are divided into multiple query groupsaccording to operators of each logical query plan tree. The logicalquery plan trees in each query group obtained after the division havethe following relationship: an inter-query write-read dependencyrelationship, an operator overlap relationship, or an operand overlaprelationship. Then, the inter-query optimization is performed on thelogical query plan trees in each query group, and multiple correspondingphysical query plan trees are generated according to the multipleoptimized logical query plan trees. Finally, physical queries areexecuted according to the multiple physical query plan trees to obtainquery results of the multiple query statements. According to theforegoing method, the multiple logical query plan trees are grouped toincrease an optimization opportunity between the logical query plantrees in the query group, and inter-query optimization is furtherperformed on the logical query plan trees in the query group to improvequery efficiency of a batch data query.

BRIEF DESCRIPTION OF THE DRAWINGS

To describe the technical solutions in the embodiments of the presentdisclosure more clearly, the following briefly describes theaccompanying drawings required for describing the embodiments.

FIG. 1 is a flowchart of a batch data query method according to a firstembodiment of the present disclosure;

FIG. 2A and FIG. 2B are a flowchart of a batch data query methodaccording to a second embodiment of the present disclosure;

FIG. 3 is a flowchart of a batch data query method according to a thirdembodiment of the present disclosure;

FIG. 4 is a schematic structural diagram of a batch data query apparatusaccording to a fourth embodiment of the present disclosure;

FIG. 5 is a schematic structural diagram of a batch data query apparatusaccording to a fifth embodiment of the present disclosure; and

FIG. 6 is a schematic structural diagram of a batch data query apparatusaccording to a sixth embodiment of the present disclosure.

DETAILED DESCRIPTION OF ILLUSTRATIVE EMBODIMENTS

To make the objectives, technical solutions, and advantages of theembodiments of the present disclosure clearer, the following clearlydescribes the technical solutions in the embodiments of the presentdisclosure with reference to the accompanying drawings in theembodiments of the present disclosure. Apparently, the describedembodiments are some but not all of the embodiments of the presentdisclosure.

Methods in the embodiments of the present disclosure are mainly appliedto a batch data query scenario, for example, may be applied to a datawarehouse. A large quantity of batch data query opportunities exists inthe data warehouse. A large amount of data exists in the data warehouse.The data is usually stored in a distributed file system.

FIG. 1 is a flowchart of a batch data query method according to a firstembodiment of the present disclosure. A method provided in thisembodiment may be executed by a batch data query apparatus. The batchdata query apparatus is specifically a database server. As shown in FIG.1, the method in this embodiment may include the following steps.

Step 101: Obtain multiple logical query plan trees corresponding tomultiple query statements, where each query statement is correspondingto one logical query plan tree, each logical query plan tree in themultiple logical query plan trees includes multiple operators, and eachoperator of each logical query plan tree includes at least one operand.

Each query statement sent by a client is parsed into a logical queryplan tree of a tree-like structure by a server side. The logical queryplan tree includes multiple nodes. Each node is corresponding to oneoperator. Each operator includes one or more operands. Frequently usedoperators include a scan operator, a sort operator, a select operator,an aggregate operator, a product operator, a join operator, a filesinkoperator, and the like.

Step 102: Divide the multiple logical query plan trees into multiplequery groups according to operators of each logical query plan tree,where logical query plan trees in each query group have the followingrelationship: an inter-query write-read dependency relationship, anoperator overlap relationship, or an operand overlap relationship.

In this embodiment, if a data identifier of an operand whose value isdetermined by a filesink operator from one logical query plan tree isthe same as a data identifier of a specific operand of a scan operatorfrom another logical query plan tree, the two logical query plan treeshave a write-read dependency relationship. If operators of one logicalquery plan tree are the same as those of another logical query plantree, the two logical query plan trees have an operator overlaprelationship. If data identifiers of all or some operands of one logicalquery plan tree are the same as those of another logical query plantree, the two logical query plan trees have an operand overlaprelationship. A quantity of same operators that the two logical queryplan trees having the operator overlap relationship have is referred toas an operator overlapping degree. A quantity of same data identifiersthat the two logical query plan trees having the operand overlaprelationship have is referred to as an operand overlapping degree.

The method in this embodiment is as follows: based on a result ofinter-query flow analysis, a data identifier is added for each operandof each operator of each logical query plan tree in the multiple logicalquery plan trees by using the flow analysis, so as to determine awrite-read dependency relationship, an operator overlap relationship,and an operand overlap relationship between the logical query plan treesaccording to operators of each logical query plan tree and dataidentifiers of operands of the operators when optimization is performedon the multiple logical query plan trees; and then, the multiple logicalquery plan trees are grouped according to any one or a combination ofthe write-read dependency relationship, the operator overlaprelationship, or the operand overlap relationship between the logicalquery plan trees, so that logical query plan trees in each query groupobtained after the grouping have the following relationship: theinter-query write-read dependency relationship, the operator overlaprelationship, or the operand overlap relationship. Optionally, the dataidentifier may be specifically a version number of an operand.

In this embodiment, the multiple logical query plan trees are grouped toincrease an optimization opportunity between the logical query plantrees in each query group obtained after the grouping, so as tofacilitate a next step of performing inter-query optimization on thelogical query plan trees in each query group. For example, grouping isperformed according to the inter-query write-read dependencyrelationship, so that logical query plan trees that have the inter-querywrite-read dependency relationship can be grouped into a query group;then, inter-query optimization is performed on the logical query plantrees according to the inter-query write-read dependency relationship,so as to avoid frequently performing a read/write operation on adistributed file system. Alternatively, grouping is performed accordingto the operator overlap relationship, so that logical query plan treesthat have a common query subtree can be grouped into a query group;then, a result of the common query subtree may be reused wheninter-query optimization is performed. Alternatively, grouping isperformed according to the operand overlap relationship, so that logicalquery plan trees with a high operand overlapping degree can be groupedinto a group; operators that have a same data identifier are combinedinto a task when inter-query optimization is performed, so as to reducean overhead of accessing or operating same data.

In addition, each group has a relatively small quantity of logical queryplan trees due to the grouping, so that costs and complexity ofinter-query optimization can be reduced. As a result, batch queryefficiency is improved, and optimization costs of a logical query planare reduced.

Step 103: Perform inter-query optimization on the logical query plantrees in each query group.

The inter-query optimization is to perform optimization on multiplelogical query plan trees in a query group as a whole, rather thanperforming optimization on a single logical query plan tree. That is, anoptimization opportunity exists between the logical query plan trees.There are mainly the following three optimization opportunities when theinter-query optimization is performed.

A first optimization opportunity is a common query subtree, which isalso referred to as a common subquery. The optimization opportunity isfor logical query plan trees that have an operator overlap relationship.If in a query group, a tree structure of a first query subtree of onelogical query plan tree is the same as that of a second query subtree ofanother logical query plan tree, and a data identifier of an operand ofeach operator of the first query subtree is the same as a dataidentifier of an operand of each operator of the second query subtree,when the first query subtree is executed before the second querysubtree, the first query subtree is referred to as a common querysubtree, and the second query subtree is referred to as a copy of thefirst query subtree; or when the first query subtree is executed afterthe second query subtree, the second query subtree is referred to as acommon query subtree, and the first query subtree is referred to as acopy of the second query subtree.

Because the tree structure of the first query subtree is the same asthat of the second query subtree, and all the operands of the firstquery subtree are the same as those of the second query subtree, it canbe learned that a query result of the first query subtree is the same asthat of the second query subtree. Therefore, an optimization opportunityfor this scenario is to reuse the query result of the first querysubtree and the query result of the second query subtree.

When the inter-query optimization is performed, an optimizationopportunity of the common query subtree needs to be first recognized.Specifically, whether in each query group, a tree structure of a firstquery subtree is the same as that of a second query subtree isdetermined. The first query subtree and the second query subtree belongto two different logical query plan trees in a same query group. If thetree structure of the first query subtree is the same as that of thesecond query subtree, whether a data identifier of an operand of anoperator of the first query subtree is the same as a data identifier ofan operand of an operator of the second query subtree is furtherdetermined. If the data identifier of the operand of the operator of thefirst query subtree is the same as the data identifier of the operand ofthe operator of the second query subtree, the first query subtree andthe second query subtree are common query subtrees. The optimizationopportunity of the common query subtree is recognized.

After the optimization opportunity of the common query subtree isrecognized, optimization is performed on the first query subtree and thesecond query subtree. Specifically, if the first query subtree isexecuted before the second query subtree, a successor of the secondquery subtree is connected to the first query subtree, the successor ofthe second query subtree is used as a newly-added successor of the firstquery subtree, and the first query subtree is deleted, so that thesuccessor of the second query subtree reuses a query result of the firstquery subtree. Alternatively, if the first query subtree is executedafter the second query subtree, a successor of the first query subtreeis connected to the second query subtree, the successor of the firstquery subtree is used as a newly-added successor of the second querysubtree, and the second query subtree is deleted, so that the successorof the first query subtree reuses a query result of the second querysubtree.

Optimization is performed according to the optimization opportunity ofthe common query subtree, to avoid repeatedly querying a same queryresult. Therefore, a database query overhead is reduced, and databasequery efficiency is improved.

A second optimization opportunity is query inlining. The query inliningis an optimization opportunity for two logical query plan trees thathave an inter-query write-read dependency relationship. In a distributedstorage system, when written data is relatively large, a filesinkoperator and a scan operator occupy a high overhead. In this embodiment,optimization is performed on the two logical query plan trees that havethe inter-query write-read dependency relationship, to reduce theoverhead of the filesink operator and the scan operator.

The query inlining opportunity needs to be first recognized.Specifically, whether a data identifier of an operand corresponding to afilesink operator is the same as a data identifier of an operandcorresponding to a scan operator in each query group is determined. Thescan operator and the filesink operator belong to two different logicalquery plan trees in a same query group. If the data identifier of theoperand corresponding to the filesink operator is the same as the dataidentifier of the operand corresponding to the scan operator, thelogical query plan tree to which the filesink operator belongs has aninter-query write-read dependency relationship with the logical queryplan tree to which the scan operator belongs. After the query inliningopportunity is recognized, the following optimization is performedaccording to the query inlining opportunity: directly connecting apredecessor of the filesink operator to a successor of the scanoperator, and deleting the scan operator.

For example, for a pair of operators <OPw, OPr> that have an inter-querywrite-read dependency relationship, OPw indicates a filesink operator,OPr indicates a scan operator, and OPw and OPr respectively belong totwo logical query plan trees. When inter-query optimization is notperformed, after a predecessor of OPw is executed, OPw writes an outputresult of the predecessor of OPw into a distributed file system. Then,when OPr is executed, the output result of the predecessor of OPw needsto be read from the distributed file system, and a successor of OPrprocesses the read output result of the predecessor of OPw. A largeamount of time needs to be taken to read/write data from/into thedistributed file system, thereby reducing data query efficiency. In thisembodiment, to reduce a read/write overhead in the distributed filesystem, a new predecessor-successor relationship is established betweenthe predecessor of OPw and the successor of OPr. That is, the successorof OPr is directly connected to the predecessor of OPw, and thesuccessor of OPr is used as a successor of the predecessor of OPw. Inthis way, after the predecessor of OPw is executed, the output result ofthe predecessor of OPw is directly used as input of the successor of OPrfor processing, so that the output result of the predecessor of OPw doesnot need to be first written into the distributed file system and thenbe read. Therefore, the read/write overhead in the distributed filesystem is reduced, and query efficiency is improved.

When query inlining optimization is performed, the predecessor of OPw isdirectly connected to the successor of OPr, and OPr is deleted, so thatthe logical query plan tree to which OPw belongs and the logical queryplan tree to which OPr belongs are combined into one logical query plantree. The combined logical query plan tree may introduce new intra-queryoptimization. The intra-query optimization is optimization for a singlelogical query plan tree, typically, for example, a task-flow correlationoptimization opportunity. After the new intra-query optimization isintroduced, intra-query optimization may be performed on the combinedlogical query plan tree.

A third optimization opportunity is a correlation subquery (orCorrelation Query Subtree). The optimization opportunity is for logicalquery plan trees that have an operand overlap relationship. If twooperators of a first operator and a second operator exist in a querygroup, the first operator and the second operator belong to twodifferent logical query plan trees in the same query group, and operandsof the first operator and those of the second operator overlap, that is,some or all data identifiers of the operands of the first operator arethe same as data identifiers of the operands of the second operator, thefirst operator and the second operator are referred to as mutualcorrelation subqueries.

The correlation subquery optimization opportunity needs to be firstrecognized. Specifically, whether in each query group, a data identifierof an operand of a first operator is the same as a data identifier of anoperand of a second operator is determined. The first operator and thesecond operator belong to two different logical query plan trees in asame query group. If a data identifier of an operand of the firstoperator is the same as a data identifier of an operand of the secondoperator, the first operator and the second operator have a correlationsubquery optimization opportunity.

After the correlation subquery optimization opportunity is recognized,optimization is performed according to the correlation subqueryoptimization opportunity: adding a combination identifier for the firstoperator and the second operator, so that the first operator and thesecond operator are combined into a same task when a physical query plantree is generated, so as to reduce an overhead of performing a scanoperation on overlapped data.

Specifically, the combination identifier may be added for the firstoperator and the second operator in the following two manners. In onemanner, same identifier information is directly added for the firstoperator and the second operator. When a physical query plan tree isgenerated, if the two operators have the same identifier information,the two operators are combined into a same task. In the other manner, acommon successor is added for the first operator and the secondoperator, an original successor of the first operator and that of thesecond operator are used as successors of the common successor, and thecommon successor is used as a combination identifier. When a physicalquery plan tree is generated, if the two operators have a commonsuccessor, the two operators are combined into a same task. The commonsuccessor may be a new operator type to be distinguished from anexisting operator. The common successor does not have an actualoperation function, but merely records a correspondence between thefirst operator and the original successor of the first operator and acorrespondence between the second operator and the original successor ofthe second operator.

Step 104: Generate multiple physical query plan trees corresponding tothe multiple optimized logical query plan trees.

After the inter-query optimization is performed on the logical queryplan trees in the query group, the multiple logical query plan trees areobtained after the inter-query optimization. Then, multiple physicalquery plan trees are generated according to the multiple logical queryplan trees obtained after the inter-query optimization. That acorresponding physical query plan tree is generated according to thelogical query plan tree is the prior art, and details are not furtherdescribed herein.

Step 105: Execute physical queries according to the multiple physicalquery plan trees, to obtain query results of the multiple querystatements.

According to this embodiment, multiple logical query plan trees ofmultiple query statements are obtained, and the multiple logical queryplan trees are divided into multiple query groups according to operatorsof each logical query plan tree. Logical query plan trees in each querygroup obtained after the division have the following relationship: aninter-query write-read dependency relationship, an operator overlaprelationship, or an operand overlap relationship. Then, inter-queryoptimization is performed on the logical query plan trees in each querygroup, and multiple corresponding physical query plan trees aregenerated according to the multiple optimized logical query plan trees.Finally, physical queries are executed according to the multiplephysical query plan trees, to obtain query results of the multiple querystatements. According to the foregoing method, the multiple logicalquery plan trees are grouped to increase an optimization opportunitybetween the logical query plan trees in the query group, and inter-queryoptimization is performed on the logical query plan trees in the querygroup to improve query efficiency of a batch data query.

FIG. 2A and FIG. 2B are a flowchart of a batch data query methodaccording to a second embodiment of the present disclosure. In thisembodiment, step 102 in the first embodiment is mainly described indetail. As shown in FIG. 2A and FIG. 2B, the method in this embodimentmay include the following steps.

Step 201: Obtain multiple logical query plan trees corresponding tomultiple query statements, where each query statement is correspondingto one logical query plan tree, each logical query plan tree in themultiple logical query plan trees includes multiple operators, eachoperator of each logical query plan tree includes at least one operand,each operand has a data identifier, and same operands have a same dataidentifier.

For a specific implementation manner of this step, reference may be madeto related description in the first embodiment. Details are notdescribed herein again.

Step 202: Determine an inter-query write-read dependency relationshipbetween the logical query plan trees according to operators of eachlogical query plan tree and data identifiers of operands of theoperators of each logical query plan tree, group, into a first group,all logical query plan trees that have the inter-query write-readdependency relationship, group, into a second group, all logical queryplan trees that do not have the inter-query write-read dependencyrelationship, and divide the logical query plan trees in the first groupinto at least one query group according to the inter-query write-readdependency relationship between the logical query plan trees in thefirst group.

In an implementation manner, if a flow analysis result includes a dataidentifier of each operand, a filesink operator in each logical queryplan tree is first recognized. Then, whether a data identifier of eachoperand whose value is determined by the filesink operator of eachlogical query plan tree is the same as a data identifier of each operandof a scan operator of another logical query plan tree in the multiplelogical query plan trees is separately determined. If the dataidentifier of each operand whose value is determined by the filesinkoperator of each logical query plan tree is the same as the dataidentifier of each operand of the scan operator of the another logicalquery plan tree in the multiple logical query plan trees, the logicalquery plan tree including the filesink operator has an inter-querywrite-read dependency relationship with the logical query plan treeincluding the scan operator.

In another manner, if a flow analysis result includes an inter-querywrite-read dependency relationship between operators from differentlogical query plan trees, an inter-query write-read dependencyrelationship exists between logical query plan trees to which each pairof operators having an inter-query write-read dependency relationshipbelong.

In this embodiment, the multiple logical query plan trees may benumbered, and an inter-query write-read dependency relationship betweenthe logical query plan trees is successively determined in a sequence ofnumbers. For example, there are 10 logical query plan trees, and numbersare successively 1 to 10. In this case, an inter-query write-readdependency relationship between the logical query plan trees is firstdetermined. First, whether a destination path of a filesink operator inthe first logical query plan tree is empty is determined. Then, if adestination path of a filesink operator in the first logical query plantree is not empty, whether a data identifier of an operand whose valueis determined by the filesink operator in the first logical query plantree is the same as a data identifier of at least one of all operands ofa scan operator in the second logical query plan tree is determined. Ifthe data identifier of the operand whose value is determined by thefilesink operator in the first logical query plan tree is the same asthe data identifier of the at least one of all the operands of the scanoperator in the second logical query plan tree, the first logical queryplan tree has an inter-query write-read dependency relationship with thesecond logical query plan tree. Then, whether the first logical queryplan tree has inter-query write-read dependency relationships with eachof the eight remaining logical query plan trees is successivelydetermined. After the inter-query write-read dependency relationshipbetween the first logical query plan tree and other logical query plantrees is determined, an inter-query write-read dependency relationshipbetween the second logical query plan tree and other logical query plantrees is determined. The inter-query write-read dependency relationshipbetween the logical query plan trees is successively determinedaccording to the foregoing method. In addition, when a logical queryplan tree includes no filesink operator, the logical query plan tree isskipped, and an inter-query write-read dependency relationship between anext logical query plan tree and other logical query plan trees isdetermined.

Each logical query plan tree may include multiple filesink operators.Therefore, each logical query plan tree may have an inter-querywrite-read dependency relationship with multiple logical query plantrees. After the inter-query write-read dependency relationship betweenthe logical query plan trees is determined, all logical query plan treesthat are in the multiple logical query plan trees and have theinter-query write-read dependency relationship are grouped into a firstgroup, and logical query plan trees that do not have the inter-querywrite-read dependency relationship are grouped into a second group.Then, the logical query plan trees in the first group are groupedaccording to the inter-query write-read dependency relationship.Specifically, when grouping is performed, it is assumed that the firstlogical query plan tree has an inter-query write-read dependencyrelationship with both the second logical query plan tree and the sixthlogical query plan tree, and the sixth logical query plan tree has aninter-query write-read dependency relationship with the fourth logicalquery plan tree. When the grouping is performed, the first logical queryplan tree and the second logical query plan tree may be grouped into aquery group, and the sixth logical query plan tree and the fourthlogical query plan tree may be grouped into a query group; or the firstlogical query plan tree, the second logical query plan tree, the sixthlogical query plan tree, and the fourth logical query plan tree may begrouped into a query group. A specific grouping manner is not limited inthis embodiment of the present disclosure.

The logical query plan trees that have the inter-query write-readdependency relationship are divided into a query group by using thisstep, thereby increasing an optimization opportunity in the query group.

Step 203: Collect statistics about a quantity of operators in each typein each logical query plan tree in the second group, determine anoperator overlapping degree between the logical query plan treesaccording to the quantity of operators in each type in each logicalquery plan tree, group, into a first subgroup, logical query plan treesin the second group that have an operator overlap relationship, group,into a second subgroup, other logical query plan trees in the secondgroup except the logical query plan trees in the first subgroup, anddivide the logical query plan trees in the first subgroup into at leastone query group according to the operator overlapping degree between thelogical query plan trees in the first subgroup.

The operator has multiple types, for example, a join operator, anaggregate operator, and a scan operator. In this embodiment, thecollecting statistics about a quantity of operators in each type in eachlogical query plan tree in the second group is specifically collectingstatistics about a quantity of times that a join operator, an aggregateoperator, a scan operator, or the like of each logical query plan treein the second group separately appears. The determining an operatoroverlapping degree between the logical query plan trees according to thequantity of operators in each type in each logical query plan tree isspecifically: separately comparing a quantity of operators in each typein each logical query plan tree in the second group with a quantity ofoperators in each type in another logical query plan tree in the secondgroup; and if the quantities of operators in each type in the twological query plan trees in the second group are equal, using a sum ofquantities of operators in the types as an operator overlapping degreebetween the two logical query plan trees in a comparison process. Thecomparison process includes a process of comparing one logical queryplan tree with any other logical query plan tree in the second group. Ifquantities of operators in one type in the two logical query plan treesin the second group are not equal in the quantities of operators in thetypes, the operator overlapping degree between the two logical queryplan trees is 0 in this comparison process.

The example in step 202 is still used as an example. The second groupincludes six logical query plan trees: the third logical query plantree, the fifth logical query plan tree, the seventh logical query plantree, the eighth logical query plan tree, the ninth logical query plantree, and the tenth logical query plan tree. Statistics about a quantityof operators in each type in the six logical query plan trees is firstcollected. It is assumed that only statistics about quantities ofoperators in three types of a join operator, an aggregate operator, anda scan operator is collected. Then, a quantity of operators in each typein the third logical query plan tree is separately compared withquantities of operators in each type in the five other logical queryplan trees. It is assumed that in the third logical query plan tree, aquantity of join operators is 3, a quantity of aggregate operators is 5,a quantity of scan operators is 6, the quantities of operators in thetypes in the third logical query plan tree are the same as quantities ofoperators in the types in the eighth logical query plan tree, and thequantities of operators in the types in the third logical query plantree are not the same as quantities of operators in the types in each ofthe four other logical query plan trees. An operator overlapping degreebetween the third logical query plan tree and the eighth logical queryplan tree is 3+5+6=11, and operator overlapping degrees between thethird logical query plan tree and each of the four other logical queryplan trees are 0. Then, operand overlapping degrees between the fiveremaining logical query plan trees are successively determined in eachcomparison process. It is assumed that in the second group, only thequantities of operators in the types in the third logical query plantree are the same as the quantities of operators in the types in theeighth logical query plan tree, the third logical query plan tree andthe eighth logical query plan tree are grouped into a first subgroup,and the third logical query plan tree and the eighth logical query plantree are grouped into a same query group.

When there are multiple logical query plan trees in the first subgroup,the multiple logical query plan trees are divided into query groupsaccording to an operator overlapping degree between the logical queryplan trees. Logical query plan trees with a same overlapping degree aregrouped into a group. For example, there are four logical query plantrees in the first subgroup. Quantities of operators in each type in thefirst logical query plan tree and the second logical query plan tree arethe same, and an operator overlapping degree is 11. Quantities ofoperators in each type in the third logical query plan tree and thefourth logical query plan tree are the same, and an operator overlappingdegree is 13. In this case, the first logical query plan tree and thesecond logical query plan tree are grouped into one query group, and thethird logical query plan tree and the fourth logical query plan tree aregrouped into the other query group. If all the quantities of operatorsin each type in the foregoing four logical query plan trees are thesame, and all the operator overlapping degrees are the same, the fourlogical query plan trees may be grouped into one query group. In anothercase, although the operator overlapping degrees between the four logicalquery plan trees are the same, the quantities of operators in each typein the first logical query plan tree and the second logical query plantree are not completely the same as the quantities of operators in eachtype in the third logical query plan tree and the fourth logical queryplan tree. For example, in the first logical query plan tree and thesecond logical query plan tree, a quantity of join operators is 2, aquantity of scan operators is 5, and a quantity of aggregate operatorsis 4. In the third logical query plan tree and the fourth logical queryplan tree, a quantity of join operators is 4, a quantity of scanoperators is 5, and a quantity of aggregate operators is 2. Therefore,the four logical query plan trees cannot be grouped into one querygroup, the first logical query plan tree and the second logical queryplan tree need to be grouped into one query group, and the third logicalquery plan tree and the fourth logical query plan tree need to begrouped into the other query group.

Step 204: Determine an operand overlapping degree between the logicalquery plan trees in the second subgroup according to data identifiers ofoperands of operators of each logical query plan tree in the secondsubgroup, and divide the logical query plan trees in the second subgroupinto at least one query group according to the operand overlappingdegree between the logical query plan trees in the second subgroup.

In an implementation manner, the determining an operand overlappingdegree between the logical query plan trees in the second subgroupaccording to data identifiers of operands of operators of each logicalquery plan tree in the second subgroup may be specifically: separatelycomparing data identifiers of operands of operators of each logicalquery plan tree in the second subgroup with data identifiers of operandsof operators of another logical query plan tree in the second group, toobtain an operand overlapping degree between the logical query plantrees in the second subgroup in each comparison process. Each comparisonprocess includes a process of comparing one logical query plan tree inthe second subgroup with any other logical query plan tree in the secondsubgroup.

The foregoing example is still used as an example. After division isperformed according to the inter-query write-read dependencyrelationship and the operator overlap relationship between the logicalquery plan trees, for the remaining logical query plan trees in thesecond subgroup: the fifth logical query plan tree, the seventh logicalquery plan tree, the ninth logical query plan tree, and the tenthlogical query plan tree, data identifiers of operands of operators ofthe fifth logical query plan tree are first compared with dataidentifiers of operands of operators of the seventh logical query plantree. It is assumed that the fifth logical query plan tree has six typesof data identifiers in total, the seventh logical query plan tree hasfive types of data identifiers in total, and three types of dataidentifiers of the fifth logical query plan tree are the same as dataidentifiers of the seventh logical query plan tree. An operandoverlapping degree between the fifth logical query plan tree and theseventh logical query plan tree is 3. Then, an operand overlappingdegree between the fifth logical query plan tree and each of the ninthlogical query plan tree and the tenth logical query plan tree issuccessively determined. Then, an operand overlapping degree between theseventh logical query plan tree and each of the three other logicalquery plan trees is determined. The operand overlapping degree betweenthe fifth logical query plan tree and the seventh logical query plantree is determined. Therefore, when the overlapping degree of theseventh logical query plan tree is determined, the operand overlappingdegree between the seventh logical query plan tree and the fifth logicalquery plan tree does not need to be determined, and only an operandoverlapping degree between the seventh logical query plan tree and eachof the ninth logical query plan tree and the tenth logical query plantree needs to be determined. Finally, an operand overlapping degreebetween the ninth logical query plan tree and the tenth logical queryplan tree is determined.

After the operand overlapping degree between the logical query plantrees in the second subgroup in each comparison process is determined,grouping is performed according to a magnitude of the operandoverlapping degree, and logical query plan trees with a maximumoverlapping degree are preferentially grouped into one group. Forexample, the operand overlapping degree between the fifth logical queryplan tree and the seventh logical query plan tree is the maximum, andthe maximum operand overlapping degree is 5. Then, the fifth logicalquery plan tree and the seventh logical query plan tree are grouped intoone query group. If the overlapping degree between the fifth logicalquery plan tree and the ninth logical query plan tree is also 5, and theoverlapping degree between the ninth logical query plan tree and thetenth logical query plan tree is 3, the ninth logical query plan treemay also be grouped into the query group, and the query group has threelogical query plan trees in total. Because only the tenth logical queryplan tree is left, the tenth logical query plan tree may be grouped intothe query group, or the tenth logical query plan tree may beindependently grouped into a query group.

It should be noted that, that sums of overlapped operands of two logicalquery plan trees are the same does not mean that all elements of theoverlapped operands of the two logical query plan trees are the same.Therefore, after overlapping degrees between multiple logical query plantrees are the same, whether data identifiers of overlapped operandsincluded in two logical query plan trees are the same may be furtherdetermined. For example, the operand overlapping degree between thefifth logical query plan tree and the seventh logical query plan tree is5, and data identifiers of overlapped operands are respectively: dataidentifiers A, B, C, D, and E. The operand overlapping degree betweenthe fifth logical query plan tree and the ninth logical query plan treeis also 5, but data identifiers of overlapped operands are differentfrom the foregoing data identifiers of the overlapped operands. The dataidentifiers of the overlapped data of the fifth logical query plan treeand the ninth logical query plan tree include: data identifiers A, B, C,E, and F. The operand overlapping degree between the ninth logical queryplan tree and the tenth logical query plan tree is 3. Therefore, whengrouping is performed, the fifth logical query plan tree and the seventhlogical query plan tree may be grouped into one query group, and theninth logical query plan tree and the tenth logical query plan tree maybe grouped into one query group.

In another implementation manner, an operand overlapping degree betweenthe logical query plan trees in the second subgroup may be determinedaccording to data identifiers of operands of scan operators of eachlogical query plan tree in the second subgroup. Specifically, dataidentifiers of operands of a scan operator of each logical query plantree in the second subgroup are separately compared with dataidentifiers of operands of a scan operator of another logical query plantree in the second subgroup, to obtain an operand overlapping degreebetween the logical query plan trees in the second subgroup in eachcomparison process. Each comparison process includes a process ofcomparing one logical query plan tree in the second subgroup with anyother logical query plan tree in the second subgroup.

Step 205: Perform inter-query optimization on the logical query plantrees in each query group.

For a specific implementation manner of this step, reference may be madeto related description in the first embodiment. Details are notdescribed herein again.

Step 206: Generate multiple physical query plan trees corresponding tothe multiple optimized logical query plan trees.

Step 207: Execute physical queries according to the multiple physicalquery plan trees, to obtain query results of the multiple querystatements.

In this embodiment, multiple logical query plan trees are first groupedaccording to an inter-query write-read dependency relationship betweenthe logical query plan trees, and logical query plan trees that have theinter-query write-read dependency relationship are grouped into a samequery group. Then, the remaining logical query plan trees that do nothave the inter-query write-read dependency relationship are dividedaccording to an operator overlap relationship. Finally, logical queryplan trees left after the division is performed according to theinter-query write-read dependency relationship and the operator overlaprelationship are divided according to an operand overlap relationship.An optimization opportunity between logical query plan trees in a querygroup may be increased by using the foregoing method. Inter-queryoptimization is further performed on the logical query plan trees in thequery group, to improve query efficiency of a batch data query. Inaddition, each group has a relatively small quantity of logical queryplan trees due to the grouping, so that costs and complexity ofinter-query optimization can be reduced. As a result, overall costs ofquery optimization are reduced.

In the second embodiment of the present disclosure, a grouping manner isdescribed in detail by using an example in which grouping is performedaccording to three parameters: an operand overlap relationship, anoperator overlap relationship, and an inter-query write-read dependencyrelationship between logical query plan trees. This is not limited inthe present disclosure. Division may be performed according to anyparameter in the foregoing three parameters. For example, when groupingis performed according to only the inter-query write-read dependencyrelationship, logical query plan trees that have the inter-querywrite-read dependency relationship are first grouped into one querygroup, and logical query plan trees that do not have the inter-querywrite-read dependency relationship are grouped into one query group.When there are a lot of logical query plan trees that do not have theinter-query write-read dependency relationship, accordingly, the groupis oversized. In this case, the logical query plan trees that do nothave the inter-query write-read dependency relationship may be randomlydivided into some query groups. When grouping is performed according toonly the operator overlap relationship, logical query plan trees with asame quantity of operators in each type are first grouped into one querygroup, and the remaining logical query plan trees are grouped into onequery group. When grouping is performed according to the inter-querywrite-read dependency relationship and the operator overlaprelationship, grouping is first performed according to the inter-querywrite-read dependency relationship, and the remaining logical query plantrees that do not have the inter-query write-read dependencyrelationship are grouped according to the operator overlap relationship.When grouping is performed according to the inter-query write-readdependency relationship and the operand overlap relationship, groupingis first performed according to the inter-query write-read dependencyrelationship, and the remaining logical query plan trees that do nothave the inter-query write-read dependency relationship are groupedaccording to the operand overlap relationship. For a specific method forperforming grouping according to the inter-query write-read dependencyrelationship, an operand overlapping degree, or an operator overlappingdegree, reference may be made to related description in the secondembodiment. Details are not described herein again.

FIG. 3 is a flowchart of a batch data query method according to a thirdembodiment of the present disclosure. A difference between thisembodiment and the first embodiment is that in this embodiment, overalloptimization is further performed between groups after inter-queryoptimization is performed on each query group. As shown in FIG. 3, themethod of this embodiment may include the following steps.

Step 301: Obtain multiple logical query plan trees corresponding tomultiple query statements, where each query statement is correspondingto one logical query plan tree.

Step 302: Divide the multiple logical query plan trees into multiplequery groups according to operators of each logical query plan tree,where logical query plan trees in each query group have the followingrelationship: an inter-query write-read dependency relationship, anoperator overlap relationship, or an operand overlap relationship.

Step 303: Perform inter-query optimization on the logical query plantrees in each query group.

For specific implementation manners of steps 301 to 303, reference maybe made to related description in the first embodiment and that in thesecond embodiment. Details are not described herein again.

Step 304: generate a virtual logical query plan tree, where a root nodeof the virtual logical query plan tree is a virtual operation node, andwhere predecessors of root node of the virtual logical query plan treeare root nodes of the multiple logical query plan trees obtained afterthe inter-query optimization.

An objective of this step is to combine multiple logical query plantrees obtained after the inter-query optimization into one logical queryplan tree. Specifically, a virtual operation node is created, and asuccessor-predecessor relationship between the virtual operation nodeand a root node of each logical query plan tree obtained after theinter-query optimization is established. That is, the virtual operationnode is used as a root node of each logical query plan tree obtainedafter the inter-query optimization, so as to form a virtual logicalquery plan tree. An operator type represented by the virtual operationnode is a new type except an existing operator type.

Step 305: Perform intra-query optimization on the virtual logical queryplan tree to generate a virtual logical query plan tree obtained afterthe intra-query optimization.

In step 304, the multiple logical query plan trees obtained after theinter-query optimization are combined into the logical query plan tree,so that optimization can be performed on the virtual logical query plantree by using an existing intra-query optimization technology.Frequently used intra-query optimization technologies include predicatepushdown optimization, column pruning optimization, task-flowcorrelation optimization, and the like. Whether to perform optimizationon the virtual logical query plan tree may be determined according to anoptimization rule or a cost optimization model.

Step 306: Delete the virtual operation node from the virtual logicalquery plan tree obtained after the intra-query optimization, to obtainthe multiple optimized logical query plan trees.

Step 307: Generate multiple physical query plan trees corresponding tothe multiple optimized logical query plan trees.

Step 308: Execute physical queries according to the multiple physicalquery plan trees, to obtain query results of the multiple querystatements.

In this embodiment, multiple logical query plan trees obtained afterinter-query optimization are combined into one logical query plan tree,and then, intra-query optimization is performed on the combined logicalquery plan tree to further perform optimization on the multiple logicalquery plan trees, so as to improve query efficiency of a batch query.

FIG. 4 is a schematic structural diagram of a batch data query apparatusaccording to a fourth embodiment of the present disclosure. As shown inFIG. 4, the apparatus provided in this embodiment includes an obtainingmodule 11, a grouping module 12, an optimization module 13, a generationmodule 14, and a query module 15.

The obtaining module 11 is configured to obtain multiple logical queryplan trees corresponding to multiple query statements. Each querystatement is corresponding to one logical query plan tree. Each logicalquery plan tree in the multiple logical query plan trees includesmultiple operators. Each operator of each logical query plan treeincludes at least one operand.

The grouping module 12 is configured to divide the multiple logicalquery plan trees into multiple query groups according to operators ofeach logical query plan tree. Logical query plan trees in each querygroup have the following relationship: an inter-query write-readdependency relationship, an operator overlap relationship, or an operandoverlap relationship.

The optimization module 13 is configured to perform inter-queryoptimization on the logical query plan trees in each query group.

The generation module 14 is configured to generate multiple physicalquery plan trees corresponding to the multiple optimized logical queryplan trees.

The query module 15 is configured to execute physical queries accordingto the multiple physical query plan trees, to obtain query results ofthe multiple query statements.

Optionally, the optimization module 13 is specifically configured to:determine whether in each query group, a tree structure of a first querysubtree is the same as that of a second query subtree, where the firstquery subtree and the second query subtree belong to two differentlogical query plan trees in a same query group; if the tree structure ofthe first query subtree is the same as that of the second query subtree,determine whether a data identifier of an operand of an operator of thefirst query subtree is the same as a data identifier of an operand of anoperator of the second query subtree; and if the data identifier of theoperand of the operator of the first query subtree is the same as thedata identifier of the operand of the operator of the second querysubtree, and the first query subtree is executed before the second querysubtree, connect a successor of the second query subtree to the firstquery subtree, and use the second query subtree as a newly-addedsuccessor of the first query subtree, so that the successor of thesecond query subtree reuses a query result of the first query subtree;or if the data identifier of the operand of the operator of the firstquery subtree is the same as the data identifier of the operand of theoperator of the second query subtree, and the first query subtree isexecuted after the second query subtree, connect a successor of thefirst query subtree to the second query subtree, and use the successorof the first query subtree as a newly-added successor of the secondquery subtree, so that the successor of the first query subtree reuses aquery result of the second query subtree.

Optionally, the optimization module 13 is specifically configured to:determine whether a data identifier of an operand corresponding to afilesink operator is the same as a data identifier of an operandcorresponding to a scan operator in each query group, where the scanoperator and the filesink operator belong to two different logical queryplan trees in a same query group; and if the data identifier of theoperand corresponding to the filesink operator is the same as the dataidentifier of the operand corresponding to the scan operator, determinethat the logical query plan tree to which the filesink operator belongshas a write-read dependency relationship with the logical query plantree to which the scan operator belongs, directly connect a predecessorof the filesink operator to a successor of the scan operator, and deletethe scan operator.

Optionally, the optimization module 13 is specifically configured to:determine whether in each query group, a data identifier of an operandof a first operator is the same as a data identifier of an operand of asecond operator, where the first operator and the second operator belongto two different logical query plan trees in a same query group; and ifthe data identifier of the operand of the first operator is the same asthe data identifier of the operand of the second operator, add acombination identifier for the first operator and the second operator,where the combination identifier is used to combine the first operatorand the second operator when the physical query plan trees aregenerated.

The apparatus in this embodiment may be configured to execute the methodin the first method embodiment. Specific implementation manners andtechnical effects of this embodiment are similar to those of the firstmethod embodiment, and details are not described herein again.

FIG. 5 is a schematic structural diagram of a batch data query apparatusaccording to a fifth embodiment of the present disclosure. The apparatusin this embodiment is based on an apparatus structure shown in FIG. 4.Further, the grouping module 12 includes a first grouping unit 121, asecond grouping unit 122, and a third grouping unit 123.

The first grouping unit 121 is configured to: determine an inter-querywrite-read dependency relationship between the logical query plan treesaccording to the operators of each logical query plan tree and dataidentifiers of operands of the operators of each logical query plantree, group, into a first group, all logical query plan trees that havethe inter-query write-read dependency relationship, and group, into asecond group, all logical query plan trees that do not have theinter-query write-read dependency relationship.

The first grouping unit 121 is further configured to divide the logicalquery plan trees in the first group into at least one query groupaccording to the inter-query write-read dependency relationship betweenthe logical query plan trees in the first group.

The second grouping unit 122 is configured to: collect statistics abouta quantity of operators in each type in each logical query plan tree inthe second group, determine an operator overlapping degree between thelogical query plan trees according to the quantity of operators in eachtype in each logical query plan tree, group, into a first subgroup,logical query plan trees in the second group that have an operatoroverlap relationship, and group, into a second subgroup, other logicalquery plan trees in the second group except the logical query plan treesin the first subgroup.

The second grouping unit 122 is further configured to divide the logicalquery plan trees in the first subgroup into at least one query groupaccording to the operator overlapping degree between the logical queryplan trees in the first subgroup.

The third grouping unit 123 is configured to: determine an operandoverlapping degree between the logical query plan trees in the secondsubgroup according to data identifiers of operands of operators of eachlogical query plan tree in the second subgroup, and divide the logicalquery plan trees in the second subgroup into at least one query groupaccording to the operand overlapping degree between the logical queryplan trees in the second subgroup.

Optionally, the first grouping unit 121 is specifically configured to:separately determine whether a data identifier of each operand whosevalue is determined by a filesink operator of each logical query plantree is the same as a data identifier of each operand of a scan operatorof another logical query plan tree in the multiple logical query plantrees; and if the data identifier of each operand whose value isdetermined by the filesink operator of each logical query plan tree isthe same as the data identifier of each operand of the scan operator ofthe another logical query plan tree in the multiple logical query plantrees, determine that the logical query plan tree including the filesinkoperator has an inter-query write-read dependency relationship with thelogical query plan tree including the scan operator.

Optionally, the second grouping unit 122 is specifically configured to:separately compare a quantity of operators in each type in each logicalquery plan tree in the second group with a quantity of operators in eachtype in another logical query plan tree in the second group; and if thequantities of operators in each type in the two logical query plan treesin the second group are equal, use a sum of quantities of operators inthe types as an operator overlapping degree between the two logicalquery plan trees in a comparison process, where the comparison processincludes a process of comparing one logical query plan tree with anyother logical query plan tree in the second group.

Further, the optimization module 13 is further configured to: generate avirtual logical query plan tree, where a root node of the virtuallogical query plan tree is a virtual operation node, and wherepredecessors of root node of the virtual logical query plan tree areroot nodes of the multiple logical query plan trees obtained after theinter-query optimization; perform intra-query optimization on thevirtual logical query plan tree to generate a virtual logical query plantree obtained after the intra-query optimization; and delete the virtualoperation node from the virtual logical query plan tree obtained afterthe intra-query optimization, to obtain the multiple optimized logicalquery plan trees.

The apparatus in this embodiment may be configured to execute themethods in the second embodiment and the third embodiment.Implementation principles and technical effects of this embodiment ofthis embodiment are similar to those of the first method embodiment, anddetails are not described herein again.

FIG. 6 is a schematic structural diagram of a batch data query apparatusaccording to a sixth embodiment of the present disclosure. As shown inFIG. 6, a batch data query apparatus 300 in this embodiment includes aprocessor 31, a memory 32, and a system bus 33. The processor 31 and thememory 32 are connected and complete mutual communication by using thesystem bus 33. The memory 32 is configured to store a computer executioninstruction 321. The processor 31 is configured to run the computerexecution instruction 321 to execute the following method: obtainingmultiple logical query plan trees corresponding to multiple querystatements, where each query statement is corresponding to one logicalquery plan tree, each logical query plan tree in the multiple logicalquery plan trees includes multiple operators, and each operator of eachlogical query plan tree includes at least one operand; dividing themultiple logical query plan trees into multiple query groups accordingto operators of each logical query plan tree, where logical query plantrees in each query group have the following relationship: aninter-query write-read dependency relationship, an operator overlaprelationship, or an operand overlap relationship; performing inter-queryoptimization on the logical query plan trees in each query group;generating multiple physical query plan trees corresponding to themultiple optimized logical query plan trees; and executing physicalqueries according to the multiple physical query plan trees, to obtainquery results of the multiple query statements.

Optionally, the dividing the multiple logical query plan trees intomultiple query groups according to operators of each logical query plantree includes: determining an inter-query write-read dependencyrelationship between the logical query plan trees according to theoperators of each logical query plan tree and data identifiers ofoperands of the operators of each logical query plan tree, grouping,into a first group, all logical query plan trees that have theinter-query write-read dependency relationship, and grouping, into asecond group, all logical query plan trees that do not have theinter-query write-read dependency relationship; dividing the logicalquery plan trees in the first group into at least one query groupaccording to the inter-query write-read dependency relationship betweenthe logical query plan trees in the first group; collecting statisticsabout a quantity of operators in each type in each logical query plantree in the second group, determining an operator overlapping degreebetween the logical query plan trees according to the quantity ofoperators in each type in each logical query plan tree, grouping, into afirst subgroup, logical query plan trees in the second group that havean operator overlap relationship, and grouping, into a second subgroup,other logical query plan trees in the second group except the logicalquery plan trees in the first subgroup; dividing the logical query plantrees in the first subgroup into at least one query group according tothe operator overlapping degree between the logical query plan trees inthe first subgroup; and determining an operand overlapping degreebetween the logical query plan trees in the second subgroup according todata identifiers of operands of operators of each logical query plantree in the second subgroup, and dividing the logical query plan treesin the second subgroup into at least one query group according to theoperand overlapping degree between the logical query plan trees in thesecond subgroup.

In this embodiment, the determining an inter-query write-read dependencyrelationship between the logical query plan trees according to theoperators of each logical query plan tree and data identifiers ofoperands of the operators of each logical query plan tree includes:separately determining whether a data identifier of each operand whosevalue is determined by a filesink operator of each logical query plantree is the same as a data identifier of each operand of a scan operatorof another logical query plan tree in the multiple logical query plantrees; and if the data identifier of each operand whose value isdetermined by the filesink operator of each logical query plan tree isthe same as the data identifier of each operand of the scan operator ofthe another logical query plan tree in the multiple logical query plantrees, determining that the logical query plan tree including thefilesink operator has an inter-query write-read dependency relationshipwith the logical query plan tree including the scan operator.

In this embodiment, the determining an operator overlapping degreebetween the logical query plan trees according to the quantity ofoperators in each type in each logical query plan tree includes:separately comparing a quantity of operators in each type in eachlogical query plan tree in the second group with a quantity of operatorsin each type in another logical query plan tree in the second group; andif the quantities of operators in each type in the two logical queryplan trees in the second group are equal, using a sum of quantities ofoperators in the types as an operator overlapping degree between the twological query plan trees in a comparison process, where the comparisonprocess includes a process of comparing one logical query plan tree withany other logical query plan tree in the second group.

Optionally, the performing inter-query optimization on the logical queryplan trees in each query group includes: determining whether in eachquery group, a tree structure of a first query subtree is the same asthat of a second query subtree, where the first query subtree and thesecond query subtree belong to two different logical query plan trees ina same query group; if the tree structure of the first query subtree isthe same as that of the second query subtree, determining whether a dataidentifier of an operand of an operator of the first query subtree isthe same as a data identifier of an operand of an operator of the secondquery subtree; and if the data identifier of the operand of the operatorof the first query subtree is the same as the data identifier of theoperand of the operator of the second query subtree, and the first querysubtree is executed before the second query subtree, connecting asuccessor of the second query subtree to the first query subtree, andusing the second query subtree as a newly-added successor of the firstquery subtree, so that the successor of the second query subtree reusesa query result of the first query subtree; or if the data identifier ofthe operand of the operator of the first query subtree is the same asthe data identifier of the operand of the operator of the second querysubtree, and the first query subtree is executed after the second querysubtree, connecting a successor of the first query subtree to the secondquery subtree, and using the successor of the first query subtree as anewly-added successor of the second query subtree, so that the successorof the first query subtree reuses a query result of the second querysubtree.

Optionally, the performing inter-query optimization on the logical queryplan trees in each query group includes: determining whether a dataidentifier of an operand corresponding to a filesink operator is thesame as a data identifier of an operand corresponding to a scan operatorin each query group, where the scan operator and the filesink operatorbelong to two different logical query plan trees in a same query group;and if the data identifier of the operand corresponding to the filesinkoperator is the same as the data identifier of the operand correspondingto the scan operator, determining that the logical query plan tree towhich the filesink operator belongs has a write-read dependencyrelationship with the logical query plan tree to which the scan operatorbelongs, directly connecting a predecessor of the filesink operator to asuccessor of the scan operator, and deleting the scan operator.

Optionally, the performing inter-query optimization on the logical queryplan trees in each query group includes: determining whether in eachquery group, a data identifier of an operand of a first operator is thesame as a data identifier of an operand of a second operator, where thefirst operator and the second operator belong to two different logicalquery plan trees in a same query group; and if the data identifier ofthe operand of the first operator is the same as the data identifier ofthe operand of the second operator, adding a combination identifier forthe first operator and the second operator, where the combinationidentifier is used to combine the first operator and the second operatorwhen the physical query plan trees are generated.

Optionally, before the generating multiple physical query plan treescorresponding to the multiple optimized logical query plan trees, themethod further includes: generating a virtual logical query plan tree,where a root node of the virtual logical query plan tree is a virtualoperation node, and where predecessors of root node of the virtuallogical query plan tree are root nodes of the multiple logical queryplan trees obtained after the inter-query optimization; performingintra-query optimization on the virtual logical query plan tree togenerate a virtual logical query plan tree obtained after theintra-query optimization; and deleting the virtual operation node fromthe virtual logical query plan tree obtained after the intra-queryoptimization, to obtain the multiple optimized logical query plan trees.

The apparatus in this embodiment may be configured to execute thetechnical solution in any method embodiment of the first embodiment tothe third embodiment. Implementation principles and technical effects ofthis embodiment of this embodiment are similar to those of the firstmethod embodiment, and details are not described herein again.

Persons of ordinary skill in the art may understand that all or some ofthe steps of the method embodiments may be implemented by a programinstructing relevant hardware. The program may be stored in acomputer-readable storage medium. When the program runs, the steps ofthe method embodiments are performed. The foregoing storage mediumincludes: any medium that can store program code, such as a read onlymemory (ROM), a random access memory (RAM), a magnetic disk, or anoptical disc.

Finally, it should be noted that the foregoing embodiments are merelyintended for describing the technical solutions of the presentdisclosure, but not for limiting the present disclosure.

What is claimed is:
 1. A method, comprising: obtaining, by a batch dataquery apparatus, multiple logical query plan trees corresponding tomultiple query statements, wherein query statements of the multiplequery statements correspond to multiple logical query plan trees,wherein logical query plan trees of the multiple logical query plantrees comprise multiple operators, and wherein operators of the multipleoperators comprise at least one operand; dividing the multiple logicalquery plan trees into multiple query groups according to operators ofthe multiple logical query plan trees, wherein logical query plan treesin query groups of the multiple query groups have a relationshipcomprising an inter-query write-read dependency relationship, anoperator overlap relationship, or an operand overlap relationship;performing inter-query optimization on the logical query plan trees inthe query groups to produce multiple optimized logical query plan trees;generating multiple physical query plan trees corresponding to themultiple optimized logical query plan trees; and executing, by the batchdata query apparatus, physical queries according to the multiplephysical query plan trees, to obtain query results of the multiple querystatements.
 2. The method according to claim 1, wherein dividing themultiple logical query plan trees into the multiple query groupscomprises: determining an inter-query write-read dependency relationshipbetween the logical query plan trees according to the operators of thelogical query plan trees and data identifiers of operands of theoperators of the logical query plan trees; grouping, into a first group,logical query plan trees that have the inter-query write-read dependencyrelationship; grouping, into a second group, logical query plan treesthat do not have the inter-query write-read dependency relationship;dividing the logical query plan trees in the first group into at leastone query group according to the inter-query write-read dependencyrelationship between the logical query plan trees in the first group;collecting statistics about a quantity of operators in type in thelogical query plan trees in the second group; determining an operatoroverlapping degree between the logical query plan trees according to thequantity of operators in the types in the logical query plan trees inthe second group; grouping, into a first subgroup, logical query plantrees in the second group that have an operator overlap relationship;grouping, into a second subgroup, logical query plan trees in the secondgroup not in the first subgroup; dividing the logical query plan treesin the first subgroup into at least one query group according to theoperator overlapping degree between the logical query plan trees in thefirst subgroup; determining an operand overlapping degree between thelogical query plan trees in the second subgroup according to dataidentifiers of operands of operators of the logical query plan trees inthe second subgroup; and dividing the logical query plan trees in thesecond subgroup into at least one query group according to the operandoverlapping degree between the logical query plan trees in the secondsubgroup.
 3. The method according to claim 2, wherein determining theinter-query write-read dependency relationship between the logical queryplan trees comprises: separately determining whether data identifiers ofoperands having values determined by a filesink operator of the logicalquery plan trees are the same as data identifiers of operands ofoperators of a scan operator of another logical query plan tree in themultiple logical query plan trees; and determining that the logicalquery plan trees of the filesink operator has an inter-query write-readdependency relationship with the logical query plan trees of the scanoperator, in response to the data identifiers of operands having valuesdetermined by the filesink operators are the same as the dataidentifiers of operands of the scan operator of another logical queryplan tree in the multiple logical query plan trees.
 4. The methodaccording to claim 2, wherein determining the operator overlappingdegree between the logical query plan trees comprises: separatelycomparing a quantity of operators in types in the logical query plantrees in the second group with a quantity of operators in types inanother logical query plan tree in the second group; and using a sum ofquantities of operators in the types as an operator overlapping degreebetween two logical query plan trees in a comparison process, inresponse to the quantities of operators in the types in the two logicalquery plan trees in the second group are equal, wherein the comparisonprocess comprises a process of comparing one logical query plan treewith another logical query plan tree in the second group.
 5. The methodaccording to claim 1, wherein performing inter-query optimization on thelogical query plan trees in the query groups comprises: determiningwhether, in the query groups, a tree structure of a first query subtreeis the same as a tree structure of a second query subtree, wherein thefirst query subtree and the second query subtree belong to differentlogical query plan trees in a same query group; determining whether adata identifier of an operand of an operator of the first query subtreeis the same as a data identifier of an operand of an operator of thesecond query subtree, in response to the tree structure of the firstquery subtree being the same as the tree structure of the second querysubtree; and connecting a successor of the second query subtree to thefirst query subtree; and using the second query subtree as a newly-addedsuccessor of the first query subtree, in response to the data identifierof the operand of the operator of the first query subtree being the sameas the data identifier of the operand of the operator of the secondquery subtree, and wherein the first query subtree is executed beforethe second query subtree, so that the successor of the second querysubtree reuses a query result of the first query subtree.
 6. The methodaccording to claim 1, wherein performing inter-query optimization on thelogical query plan trees in the query groups comprises: determiningwhether, in the query groups, a tree structure of a first query subtreeis the same as a tree structure of a second query subtree, wherein thefirst query subtree and the second query subtree belong to differentlogical query plan trees in a same query group; determining whether adata identifier of an operand of an operator of the first query subtreeis the same as a data identifier of an operand of an operator of thesecond query subtree, in response to the tree structure of the firstquery subtree being the same as the tree structure of the second querysubtree; and connecting a successor of the first query subtree to thesecond query subtree; and using the successor of the first query subtreeas a newly-added successor of the second query subtree, in response tothe data identifier of the operand of the operator of the first querysubtree being the same as the data identifier of the operand of theoperator of the second query subtree, and wherein the first querysubtree is executed after the second query subtree, so that thesuccessor of the first query subtree reuses a query result of the secondquery subtree.
 7. The method according to claim 1, wherein performinginter-query optimization on the logical query plan trees in the querygroups comprises: determining whether a data identifier of an operandcorresponding to a filesink operator is the same as a data identifier ofan operand corresponding to a scan operator in the query groups, whereinthe scan operator and the filesink operator belong to different logicalquery plan trees in a same query group; determining that the logicalquery plan trees to which the filesink operator belongs has a write-readdependency relationship with the logical query plan trees to which thescan operator belongs, in response to the data identifier of the operandcorresponding to the filesink operator being the same as the dataidentifier of the operand corresponding to the scan operator; directlyconnecting a predecessor of the filesink operator to a successor of thescan operator; and deleting the scan operator.
 8. The method accordingto claim 1, wherein performing inter-query optimization on the logicalquery plan trees in the query groups comprises: determining whether, inthe query groups, a data identifier of an operand of a first operator isthe same as a data identifier of an operand of a second operator,wherein the first operator and the second operator belong to differentlogical query plan trees in a same query group; and adding a combinationidentifier for the first operator and the second operator, in responseto the data identifier of the operand of the first operator being thesame as the data identifier of the operand of the second operator,wherein the combination identifier is used to combine the first operatorand the second operator in response to the physical query plan treesbeing generated.
 9. The method according to claim 1, wherein the methodfurther comprises: generating a virtual logical query plan tree, whereina root node of the virtual logical query plan tree is a virtualoperation node, and wherein predecessors of root node of the virtuallogical query plan tree are root nodes of the multiple logical queryplan trees obtained after the inter-query optimization; performingintra-query optimization on the virtual logical query plan tree togenerate a virtual logical query plan tree obtained after theintra-query optimization; and deleting the virtual operation node fromthe virtual logical query plan tree obtained after the intra-queryoptimization, to obtain the multiple optimized logical query plan trees,before generating the multiple physical query plan trees correspondingto the multiple optimized logical query plan trees.
 10. A batch dataquery apparatus, comprising: a processor; and a non-transitory computerreadable storage medium storing a program for execution by theprocessor, the program including instructions to: obtain multiplelogical query plan trees corresponding to multiple query statements,wherein query statements in the multiple query statements correspond tological query plan trees, wherein the logical query plan trees in themultiple logical query plan trees comprise multiple operators, andwherein operators of the logical query plan trees comprise at least oneoperand; divide the multiple logical query plan trees into multiplequery groups according to operators of the logical query plan trees,wherein logical query plan trees in the query groups have a relationshipcomprising an inter-query write-read dependency relationship, anoperator overlap relationship, or an operand overlap relationship;perform inter-query optimization on the logical query plan trees in thequery groups to produce multiple optimized logical query plan trees;generate multiple physical query plan trees corresponding to themultiple optimized logical query plan trees; and execute physicalqueries according to the multiple physical query plan trees, to obtainquery results of the multiple query statements.
 11. The batch data queryapparatus according to claim 10, wherein the instructions furthercomprise instructions to: determine an inter-query write-read dependencyrelationship between the logical query plan trees according to theoperators of the logical query plan trees and data identifiers ofoperands of the operators of the logical query plan trees; group, into afirst group, logical query plan trees that have the inter-querywrite-read dependency relationship; group, into a second group, logicalquery plan trees that do not have the inter-query write-read dependencyrelationship; divide the logical query plan trees in the first groupinto at least one query group according to the inter-query write-readdependency relationship between the logical query plan trees in thefirst group; collect statistics about a quantity of operators in typesin the logical query plan trees in the second group; determine anoperator overlapping degree between the logical query plan treesaccording to the quantity of operators in the types in the logical queryplan tree; group, into a first subgroup, logical query plan trees in thesecond group that have an operator overlap relationship; group, into asecond subgroup, logical query plan trees in the second group that arenot in the first subgroup; divide the logical query plan trees in thefirst subgroup into at least one query group according to the operatoroverlapping degree between the logical query plan trees in the firstsubgroup; determine an operand overlapping degree between the logicalquery plan trees in the second subgroup according to data identifiers ofoperands of operators of the logical query plan trees in the secondsubgroup; and divide the logical query plan trees in the second subgroupinto at least one query group according to the operand overlappingdegree between the logical query plan trees in the second subgroup. 12.The batch data query apparatus according to claim 11, wherein theinstructions further comprise instructions to: separately determinewhether a data identifier of operands having values determined by afilesink operator of the logical query plan trees is the same as a dataidentifier of operands of a scan operator of another logical query plantree in the multiple logical query plan trees; and determine that thelogical query plan trees comprising the filesink operator has aninter-query write-read dependency relationship with the logical queryplan trees of the scan operator, in response to the data identifier ofoperands having values determined by the filesink operator of thelogical query plan trees is the same as the data identifier of operandsof the scan operator of another logical query plan tree in the multiplelogical query plan trees.
 13. The batch data query apparatus accordingto claim 11, wherein the instructions further comprise instructions to:separately compare a quantity of operators in types in the logical queryplan trees in the second group with a quantity of operators in type inanother logical query plan tree in the second group; and use a sum ofquantities of operators in the types as an operator overlapping degreebetween the logical query plan trees in a comparison process, inresponse to the quantities of operators in the types in the logicalquery plan trees in the second group are equal, wherein the comparisonprocess comprises a process of comparing one logical query plan treewith any another logical query plan tree in the second group.
 14. Thebatch data query apparatus according to claim 10, wherein theinstructions further comprise instructions to: determine whether, in thequery groups, a tree structure of a first query subtree is the same as atree structure of a second query subtree, wherein the first querysubtree and the second query subtree belong to different logical queryplan trees in a same query group; determine whether a data identifier ofan operand of an operator of the first query subtree is the same as adata identifier of an operand of an operator of the second querysubtree, in response to the tree structure of the first query subtreebeing the same as the tree structure of the second query subtree;connect a successor of the second query subtree to the first querysubtree; and use the second query subtree as a newly-added successor ofthe first query subtree, in response to the data identifier of theoperand of the operator of the first query subtree being the same as thedata identifier of the operand of the operator of the second querysubtree, and wherein the first query subtree is executed before thesecond query subtree, so that the successor of the second query subtreereuses a query result of the first query subtree.
 15. The batch dataquery apparatus according to claim 10, wherein the instructions furthercomprise instructions to: determine whether, in the query groups, a treestructure of a first query subtree is the same as a tree structure of asecond query subtree, wherein the first query subtree and the secondquery subtree belong to different logical query plan trees in a samequery group; determine whether a data identifier of an operand of anoperator of the first query subtree is the same as a data identifier ofan operand of an operator of the second query subtree, in response tothe tree structure of the first query subtree being the same as the treestructure of the second query subtree; connect a successor of the firstquery subtree to the second query subtree; and use the successor of thefirst query subtree as a newly-added successor of the second querysubtree, in response to the data identifier of the operand of theoperator of the first query subtree being the same as the dataidentifier of the operand of the operator of the second query subtree,and wherein the first query subtree is executed after the second querysubtree, so that the successor of the first query subtree reuses a queryresult of the second query subtree.
 16. The batch data query apparatusaccording to claim 10, wherein the instructions further compriseinstructions to: determine whether a data identifier of an operandcorresponding to a filesink operator is the same as a data identifier ofan operand corresponding to a scan operator in the query groups, whereinthe scan operator and the filesink operator belong to different logicalquery plan trees in a same query group; determine that the logical queryplan trees to which the filesink operator belongs has a write-readdependency relationship with the logical query plan trees to which thescan operator belongs, in response to the data identifier of the operandcorresponding to the filesink operator being the same as the dataidentifier of the operand corresponding to the scan operator; directlyconnect a predecessor of the filesink operator to a successor of thescan operator; and delete the scan operator.
 17. The batch data queryapparatus according to claim 10, wherein the instructions furthercomprise instructions to: determine whether, in the query groups, a dataidentifier of an operand of a first operator is the same as a dataidentifier of an operand of a second operator, wherein the firstoperator and the second operator belong to different logical query plantrees in a same query group; and add a combination identifier for thefirst operator and the second operator, in response to the dataidentifier of the operand of the first operator being the same as thedata identifier of the operand of the second operator, wherein thecombination identifier is used to combine the first operator and thesecond operator, in response to the physical query plan trees beinggenerated.
 18. The batch data query apparatus according to claim 10,wherein the instructions further comprise instructions to: generate avirtual logical query plan tree, wherein a root node of the virtuallogical query plan tree is a virtual operation node, and whereinpredecessors of root node of the virtual logical query plan tree areroot nodes of the multiple logical query plan trees obtained after theinter-query optimization; perform intra-query optimization on thevirtual logical query plan tree to generate a virtual logical query plantree obtained after the intra-query optimization; and delete the virtualoperation node from the virtual logical query plan tree obtained afterthe intra-query optimization, to obtain the multiple optimized logicalquery plan trees.
 19. A non-transitory computer readable storage mediumstoring a program for execution by a processor of a batch data queryapparatus, the program including instructions to: obtain multiplelogical query plan trees corresponding to multiple query statements,wherein query statements in the multiple query statements correspond tological query plan trees, wherein the logical query plan trees in themultiple logical query plan trees comprise multiple operators, andwherein operators of the logical query plan trees comprise at least oneoperand; divide the multiple logical query plan trees into multiplequery groups according to operators of the logical query plan trees,wherein logical query plan trees in the query groups have a relationshipcomprising an inter-query write-read dependency relationship, anoperator overlap relationship, or an operand overlap relationship;perform inter-query optimization on the logical query plan trees in thequery groups to produce multiple optimized logical query plan trees;generate multiple physical query plan trees corresponding to themultiple optimized logical query plan trees; and execute physicalqueries according to the multiple physical query plan trees, to obtainquery results of the multiple query statements.